<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <span>{{ msg }}</span>
        <input type="text">
        <button @click="fn()">修改</button>
        <button @click="destroy()">销毁</button>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                msg: 'hello'
            },
            methods: {
                fn() {
                    this.msg += 1
                },
                destroy() {
                    this.$destroy()
                }
            },
            // 1. 创建阶段(准备数据)
            beforeCreate() {
                console.log('beforeCreate 响应式数据准备好之前', this.msg)
            },
            created() {
                console.log('created 响应式数据准备好之后', this.msg)
            },
            // 2. 挂载阶段(渲染模板)
            beforeMount() {
                console.log('beforeMount 模板渲染之前', document.querySelector('span').innerHTML)
            },
            mounted() {
                document.querySelector('input').focus()
                console.dir(document.querySelector('input'))
                console.log('mounted 模板渲染之后', document.querySelector('span').innerHTML)
            },
            // 3. 更新阶段(修改数据 → 更新视图)
            beforeUpdate() {
                console.log('beforeUpdate 数据修改了，视图还没更新', document.querySelector('span').innerHTML)
            },
            updated() {
                console.log('updated 数据修改了，视图还没更新', document.querySelector('span').innerHTML)
            },
            // 4. 销毁阶段(销毁视图)
            beforeDestroy() {
                console.log('beforeDestroy 销毁之前', document.querySelector('span').innerHTML)
            },
            destroyed() {
                console.log('destroyed 销毁之后', document.querySelector('span').innerHTML)
            }
        })

    </script>
</body>

</html>